﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace WindowsFormsApplication1
{
    public partial class adminjx : Form
    {
        dbutils db = new dbutils();
        public adminjx()
        {
            InitializeComponent();
        }



        private void button1_Click(object sender, EventArgs e)
        {
            List<string> staffids = db.select_staffid_set();
            if (staffids == null)
            {
                MessageBox.Show("error!");
                return;
            }
            string sql1 = "delete from jx";
            if (db.insert(sql1) == 0)
            {

                MessageBox.Show("error!");
                MessageBox.Show(sql1);
                return;
            }
            foreach (string staffid in staffids)
            {
                string sql = "insert into jx values('"+staffid+"',"+
                            "(select name from staff where loginname='" + staffid + "')," +
                            "(select sum(checkin_num) from kq_month_table where staffid='" + staffid + "')," +
                            "(select sum(leave_num) from kq_month_table where staffid='" + staffid + "')," +
                            "(select grade from px_cj_table where staffid='" + staffid + "')," +
                            "(select grade from pingjia where staffid='" + staffid + "')" +
                            ")";
                if (db.insert(sql) == 0)
                {

                    MessageBox.Show("error!");
                    MessageBox.Show(sql);
                    return;
                }
                
            }
            MessageBox.Show("操作成功！");
            load_data();

        }
        private void load_data()
        {
            string connection;
            string query;
            DataSet myds;
            connection = dbutils.constr;
            query = "select * from jx";
            MySqlConnection conn = new MySqlConnection(connection);
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            conn.Open();
            adapter.SelectCommand = new MySqlCommand(query, conn);
            myds = new DataSet();
            adapter.Fill(myds, "Bill");
            bindingSource1.DataSource = myds.Tables["Bill"];
            dataGridView1.DataSource = bindingSource1;
            dataGridView1.Columns["checkin_num"].HeaderText = "签到天数总计";
            dataGridView1.Columns["staffid"].HeaderText = "员工编号";
            dataGridView1.Columns["staffname"].HeaderText = "员工姓名";
            dataGridView1.Columns["leave_num"].HeaderText = "请假天数总计";
            dataGridView1.Columns["px_grade"].HeaderText = "培训分数";
            dataGridView1.Columns["pj_grade"].HeaderText = "评价分数";
            conn.Close();


        }

        private void adminjx_Load(object sender, EventArgs e)
        {
            load_data();
        }

       
    }
}
